package svc

import (
	"UserServer/rpc/internal/config"
	"github.com/redis/go-redis/v9"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

// 服务上下文,搭建一个好的服务

type ServiceContext struct {
	Config config.Config
	DB     *gorm.DB
	Cache  *redis.Client
	Logger *zap.Logger
}

func NewServiceContext(c config.Config) *ServiceContext {
	Log := InitLogger(c.Zap)
	Db := InitGorm(c.Mysql, Log)
	Rdb := InitRedis(c.Redis, Log)
	//Db.AutoMigrate(&database.JwtBlacklist{})
	return &ServiceContext{
		Config: c,
		DB:     Db,
		Cache:  Rdb,
		Logger: Log,
	}
}
